package com.jackstraw.jack_base.datasource.redis.service.impl;


import com.jackstraw.jack_base.datasource.redis.bean.RedisRouting;
import com.jackstraw.jack_base.datasource.redis.service.RedisService;
import org.redisson.api.RLock;
import org.springframework.context.annotation.Primary;
import org.springframework.data.redis.connection.DataType;
import org.springframework.data.redis.core.Cursor;
import org.springframework.data.redis.core.ScanOptions;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.stereotype.Component;

import java.time.Instant;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;

@Primary
@Component
public class RedisServiceImpl implements RedisService {

    public RedisServiceImpl(RedisRouting redisRouting) {
        this.redisRouting = redisRouting;
    }

    private RedisRouting redisRouting;


    protected RedisRouting redisRouting() {

        return redisRouting;
    }


    @Override
    public RLock lock(String lockKey) {
        return redisRouting().determineTargetEntity().lock(lockKey);
    }

    @Override
    public RLock lock(String lockKey, long leaseTime) {
        return redisRouting().determineTargetEntity().lock(lockKey, leaseTime);
    }

    @Override
    public RLock lock(String lockKey, TimeUnit unit, long timeout) {
        return redisRouting().determineTargetEntity().lock(lockKey, unit, timeout);
    }

    @Override
    public boolean tryLock(String lockKey, TimeUnit unit, long waitTime, long leaseTime) {
        return redisRouting().determineTargetEntity().tryLock(lockKey, unit, waitTime, leaseTime);
    }

    @Override
    public void unlock(String lockKey) {
        redisRouting().determineTargetEntity().unlock(lockKey);
    }

    @Override
    public void unlock(RLock lock) {
        redisRouting().determineTargetEntity().unlock(lock);
    }

    @Override
    public void delete(String key) {
        redisRouting().determineTargetEntity().delete(key);
    }

    @Override
    public void delete(Collection<String> keys) {
        redisRouting().determineTargetEntity().delete(keys);
    }

    @Override
    public byte[] dump(String key) {
        return redisRouting().determineTargetEntity().dump(key);
    }

    @Override
    public Boolean hasKey(String key) {
        return redisRouting().determineTargetEntity().hasKey(key);
    }

    @Override
    public Boolean expire(String key, long timeout, TimeUnit unit) {
        return redisRouting().determineTargetEntity().expire(key, timeout, unit);
    }

    @Override
    public Boolean expireAt(String key, Date date) {
        return redisRouting().determineTargetEntity().expireAt(key, date);
    }

    @Override
    public Boolean expireAt(String key, Instant instant) {
        return redisRouting().determineTargetEntity().expireAt(key, instant);
    }

    @Override
    public Set<String> keys(String pattern) {
        return redisRouting().determineTargetEntity().keys(pattern);
    }

    @Override
    public Boolean move(String key, int dbIndex) {
        return redisRouting().determineTargetEntity().move(key, dbIndex);
    }

    @Override
    public Boolean persist(String key) {
        return redisRouting().determineTargetEntity().persist(key);
    }

    @Override
    public Long getExpire(String key, TimeUnit unit) {
        return redisRouting().determineTargetEntity().getExpire(key, unit);
    }

    @Override
    public Long getExpire(String key) {
        return redisRouting().determineTargetEntity().getExpire(key);
    }

    @Override
    public Object randomKey() {
        return redisRouting().determineTargetEntity().randomKey();
    }

    @Override
    public void rename(String oldKey, String newKey) {
        redisRouting().determineTargetEntity().rename(oldKey, newKey);
    }

    @Override
    public Boolean renameIfAbsent(String oldKey, String newKey) {
        return redisRouting().determineTargetEntity().renameIfAbsent(oldKey, newKey);
    }

    @Override
    public DataType type(String key) {
        return redisRouting().determineTargetEntity().type(key);
    }

    @Override
    public void set(String key, Object value) {
        redisRouting().determineTargetEntity().set(key, value);
    }

    @Override
    public Object get(String key) {
        return redisRouting().determineTargetEntity().get(key);
    }

    @Override
    public String getRange(String key, long start, long end) {
        return redisRouting().determineTargetEntity().getRange(key, start, end);
    }

    @Override
    public Object getAndSet(String key, String value) {
        return redisRouting().determineTargetEntity().getAndSet(key, value);
    }

    @Override
    public Boolean getBit(String key, long offset) {
        return redisRouting().determineTargetEntity().getBit(key, offset);
    }

    @Override
    public List<Object> multiGet(Collection<String> keys) {
        return redisRouting().determineTargetEntity().multiGet(keys);
    }

    @Override
    public boolean setBit(String key, long offset, boolean value) {
        return redisRouting().determineTargetEntity().setBit(key, offset, value);
    }

    @Override
    public void setEx(String key, Object value, long timeout, TimeUnit unit) {
        redisRouting().determineTargetEntity().setEx(key, value, timeout, unit);
    }

    @Override
    public boolean setIfAbsent(String key, Object value) {
        return redisRouting().determineTargetEntity().setIfAbsent(key, value);
    }

    @Override
    public void setRange(String key, Object value, long offset) {
        redisRouting().determineTargetEntity().setRange(key, value, offset);
    }

    @Override
    public Long size(String key) {
        return redisRouting().determineTargetEntity().size(key);
    }

    @Override
    public void multiSet(Map<String, Object> maps) {
        redisRouting().determineTargetEntity().multiSet(maps);
    }

    @Override
    public boolean multiSetIfAbsent(Map<String, Object> maps) {
        return redisRouting().determineTargetEntity().multiSetIfAbsent(maps);
    }

    @Override
    public Long incrBy(String key, long increment) {
        return redisRouting().determineTargetEntity().incrBy(key, increment);
    }

    @Override
    public Long incrBy(String key) {
        return redisRouting().determineTargetEntity().incrBy(key);
    }

    @Override
    public Long decrByFloat(String key) {
        return redisRouting().determineTargetEntity().decrByFloat(key);
    }

    @Override
    public Long decrBy(String key, long increment) {
        return redisRouting().determineTargetEntity().decrBy(key, increment);
    }

    @Override
    public Double incrByFloat(String key, double increment) {
        return redisRouting().determineTargetEntity().incrByFloat(key, increment);
    }

    @Override
    public Integer append(String key, String value) {
        return redisRouting().determineTargetEntity().append(key, value);
    }

    @Override
    public Object hGet(String key, String field) {
        return redisRouting().determineTargetEntity().hGet(key, field);
    }

    @Override
    public Map<Object, Object> hGetAll(String key) {
        return redisRouting().determineTargetEntity().hGetAll(key);
    }

    @Override
    public List<Object> hMultiGet(String key, Collection<Object> fields) {
        return redisRouting().determineTargetEntity().hMultiGet(key, fields);
    }

    @Override
    public void hPut(String key, String hashKey, String value) {
        redisRouting().determineTargetEntity().hPut(key, hashKey, value);
    }

    @Override
    public void hPutAll(String key, Map<String, String> maps) {
        redisRouting().determineTargetEntity().hPutAll(key, maps);
    }

    @Override
    public Boolean hPutIfAbsent(String key, String hashKey, String value) {
        return redisRouting().determineTargetEntity().hPutIfAbsent(key, hashKey, value);
    }

    @Override
    public Long hDelete(String key, Object... fields) {
        return redisRouting().determineTargetEntity().hDelete(key, fields);
    }

    @Override
    public boolean hExists(String key, String field) {
        return redisRouting().determineTargetEntity().hExists(key, field);
    }

    @Override
    public Long hIncrBy(String key, Object field, long increment) {
        return redisRouting().determineTargetEntity().hIncrBy(key, field, increment);
    }

    @Override
    public Double hIncrByFloat(String key, Object field, double delta) {
        return redisRouting().determineTargetEntity().hIncrByFloat(key, field, delta);
    }

    @Override
    public Set<Object> hKeys(String key) {
        return redisRouting().determineTargetEntity().hKeys(key);
    }

    @Override
    public Long hSize(String key) {
        return redisRouting().determineTargetEntity().hSize(key);
    }

    @Override
    public List<Object> hValues(String key) {
        return redisRouting().determineTargetEntity().hValues(key);
    }

    @Override
    public Cursor<Map.Entry<Object, Object>> hScan(String key, ScanOptions options) {
        return redisRouting().determineTargetEntity().hScan(key, options);
    }

    @Override
    public Object lIndex(String key, long index) {
        return redisRouting().determineTargetEntity().lIndex(key, index);
    }

    @Override
    public List<Object> lRange(String key, long start, long end) {
        return redisRouting().determineTargetEntity().lRange(key, start, end);
    }

    @Override
    public Long lLeftPush(String key, String value) {
        return redisRouting().determineTargetEntity().lLeftPush(key, value);
    }

    @Override
    public Long lLeftPushAll(String key, String... value) {
        return redisRouting().determineTargetEntity().lLeftPushAll(key, value);
    }

    @Override
    public Long lLeftPushAll(String key, Collection<String> value) {
        return redisRouting().determineTargetEntity().lLeftPushAll(key, value);
    }

    @Override
    public Long lLeftPushIfPresent(String key, String value) {
        return redisRouting().determineTargetEntity().lLeftPushIfPresent(key, value);
    }

    @Override
    public Long lLeftPush(String key, String pivot, String value) {
        return redisRouting().determineTargetEntity().lLeftPush(key, pivot, value);
    }

    @Override
    public Long lRightPush(String key, String value) {
        return redisRouting().determineTargetEntity().lRightPush(key, value);
    }

    @Override
    public Long lRightPushAll(String key, String... value) {
        return redisRouting().determineTargetEntity().lRightPushAll(key, value);
    }

    @Override
    public Long lRightPushAll(String key, Collection<String> value) {
        return redisRouting().determineTargetEntity().lRightPushAll(key, value);
    }

    @Override
    public Long lRightPushIfPresent(String key, String value) {
        return redisRouting().determineTargetEntity().lRightPushIfPresent(key, value);
    }

    @Override
    public Long lRightPush(String key, String pivot, String value) {
        return redisRouting().determineTargetEntity().lRightPush(key, value);
    }

    @Override
    public void lSet(String key, long index, String value) {
        redisRouting().determineTargetEntity().lSet(key, index, value);
    }

    @Override
    public Object lLeftPop(String key) {
        return redisRouting().determineTargetEntity().lLeftPop(key);
    }

    @Override
    public Object lBLeftPop(String key, long timeout, TimeUnit unit) {
        return redisRouting().determineTargetEntity().lBLeftPop(key, timeout, unit);
    }

    @Override
    public Object lRightPop(String key) {
        return redisRouting().determineTargetEntity().lRightPop(key);
    }

    @Override
    public Object lBRightPop(String key, long timeout, TimeUnit unit) {
        return redisRouting().determineTargetEntity().lBRightPop(key, timeout, unit);
    }

    @Override
    public Object lRightPopAndLeftPush(String sourceKey, String destinationKey) {
        return redisRouting().determineTargetEntity().lRightPopAndLeftPush(sourceKey, destinationKey);
    }

    @Override
    public Object lBRightPopAndLeftPush(String sourceKey, String destinationKey, long timeout, TimeUnit unit) {
        return redisRouting().determineTargetEntity().lBRightPopAndLeftPush(sourceKey, destinationKey, timeout, unit);
    }

    @Override
    public Long lRemove(String key, long index, String value) {
        return redisRouting().determineTargetEntity().lRemove(key, index, value);
    }

    @Override
    public void lTrim(String key, long start, long end) {
        redisRouting().determineTargetEntity().lTrim(key, start, end);
    }

    @Override
    public Long lLen(String key) {
        return redisRouting().determineTargetEntity().lLen(key);
    }

    @Override
    public Long sAdd(String key, String... values) {
        return redisRouting().determineTargetEntity().sAdd(key, values);
    }

    @Override
    public Long sRemove(String key, Object... values) {
        return redisRouting().determineTargetEntity().sRemove(key, values);
    }

    @Override
    public Object sPop(String key) {
        return redisRouting().determineTargetEntity().sPop(key);
    }

    @Override
    public Boolean sMove(String key, String value, String destKey) {
        return redisRouting().determineTargetEntity().sMove(key, value, destKey);
    }

    @Override
    public Long sSize(String key) {
        return redisRouting().determineTargetEntity().sSize(key);
    }

    @Override
    public Boolean sIsMember(String key, Object value) {
        return redisRouting().determineTargetEntity().sIsMember(key, value);
    }

    @Override
    public Set<Object> sIntersect(String key, String otherKey) {
        return redisRouting().determineTargetEntity().sIntersect(key, otherKey);
    }

    @Override
    public Set<Object> sIntersect(String key, Collection<String> otherKeys) {
        return redisRouting().determineTargetEntity().sIntersect(key, otherKeys);
    }

    @Override
    public Long sIntersectAndStore(String key, String otherKey, String destKey) {
        return redisRouting().determineTargetEntity().sIntersectAndStore(key, otherKey, destKey);
    }

    @Override
    public Long sIntersectAndStore(String key, Collection<String> otherKeys, String destKey) {
        return redisRouting().determineTargetEntity().sIntersectAndStore(key, otherKeys, destKey);
    }

    @Override
    public Set<Object> sUnion(String key, String otherKeys) {
        return redisRouting().determineTargetEntity().sUnion(key, otherKeys);
    }

    @Override
    public Set<Object> sUnion(String key, Collection<String> otherKeys) {
        return redisRouting().determineTargetEntity().sUnion(key, otherKeys);
    }

    @Override
    public Long sUnionAndStore(String key, String otherKey, String destKey) {
        return redisRouting().determineTargetEntity().sUnionAndStore(key, otherKey, destKey);
    }

    @Override
    public Long sUnionAndStore(String key, Collection<String> otherKeys, String destKey) {
        return redisRouting().determineTargetEntity().sUnionAndStore(key, otherKeys, destKey);
    }

    @Override
    public Set<Object> sDifference(String key, String otherKey) {
        return redisRouting().determineTargetEntity().sDifference(key, otherKey);
    }

    @Override
    public Set<Object> sDifference(String key, Collection<String> otherKeys) {
        return redisRouting().determineTargetEntity().sDifference(key, otherKeys);
    }

    @Override
    public Long sDifference(String key, String otherKey, String destKey) {
        return redisRouting().determineTargetEntity().sDifference(key, otherKey, destKey);
    }

    @Override
    public Long sDifference(String key, Collection<String> otherKeys, String destKey) {
        return redisRouting().determineTargetEntity().sDifference(key, otherKeys, destKey);
    }

    @Override
    public Set<Object> setMembers(String key) {
        return redisRouting().determineTargetEntity().setMembers(key);
    }

    @Override
    public Object sRandomMember(String key) {
        return redisRouting().determineTargetEntity().sRandomMember(key);
    }

    @Override
    public List<Object> sRandomMembers(String key, long count) {
        return redisRouting().determineTargetEntity().sRandomMembers(key, count);
    }

    @Override
    public Set<Object> sDistinctRandomMembers(String key, long count) {
        return redisRouting().determineTargetEntity().sDistinctRandomMembers(key, count);
    }

    @Override
    public Cursor<Object> sScan(String key, ScanOptions options) {
        return redisRouting().determineTargetEntity().sScan(key, options);
    }

    @Override
    public Boolean zAdd(String key, String value, double score) {
        return redisRouting().determineTargetEntity().zAdd(key, value, score);
    }

    @Override
    public Long zAdd(String key, Set<ZSetOperations.TypedTuple<Object>> values) {
        return redisRouting().determineTargetEntity().zAdd(key, values);
    }

    @Override
    public Long zRemove(String key, Object... values) {
        return redisRouting().determineTargetEntity().zRemove(key, values);
    }

    @Override
    public Double zIncrementScore(String key, String value, double delta) {
        return redisRouting().determineTargetEntity().zIncrementScore(key, value, delta);
    }

    @Override
    public Long zRank(String key, Object value) {
        return redisRouting().determineTargetEntity().zRank(key, value);
    }

    @Override
    public Long zReverseRank(String key, Object value) {
        return redisRouting().determineTargetEntity().zReverseRank(key, value);
    }

    @Override
    public Set<Object> zRange(String key, long start, long end) {
        return redisRouting().determineTargetEntity().zRange(key, start, end);
    }

    @Override
    public Set<ZSetOperations.TypedTuple<Object>> zRangeWithScores(String key, long start, long end) {
        return redisRouting().determineTargetEntity().zRangeWithScores(key, start, end);
    }

    @Override
    public Set<Object> zRangeByScore(String key, double min, double max) {
        return redisRouting().determineTargetEntity().zRangeByScore(key, min, max);
    }

    @Override
    public Set<ZSetOperations.TypedTuple<Object>> zRangeByScoreWithScores(String key, double min, double max) {
        return redisRouting().determineTargetEntity().zRangeByScoreWithScores(key, min, max);
    }

    @Override
    public Set<ZSetOperations.TypedTuple<Object>> zRangeByScoreWithScores(String key, double min, double max, long start, long end) {
        return redisRouting().determineTargetEntity().zRangeByScoreWithScores(key, min, max, start, end);
    }

    @Override
    public Set<Object> zReverseRange(String key, long start, long end) {
        return redisRouting().determineTargetEntity().zReverseRange(key, start, end);
    }

    @Override
    public Set<ZSetOperations.TypedTuple<Object>> zReverseRangeWithScores(String key, long start, long end) {
        return redisRouting().determineTargetEntity().zReverseRangeWithScores(key, start, end);
    }

    @Override
    public Set<Object> zReverseRangeByScore(String key, double min, double max) {
        return redisRouting().determineTargetEntity().zReverseRangeByScore(key, min, max);
    }

    @Override
    public Set<ZSetOperations.TypedTuple<Object>> zReverseRangeByScoreWithScores(String key, double min, double max) {
        return redisRouting().determineTargetEntity().zReverseRangeByScoreWithScores(key, min, max);
    }

    @Override
    public Set<Object> zReverseRangeByScore(String key, double min, double max, long start, long end) {
        return redisRouting().determineTargetEntity().zReverseRangeByScore(key, min, max, start, end);
    }

    @Override
    public Long zCount(String key, double min, double max) {
        return redisRouting().determineTargetEntity().zCount(key, min, max);
    }

    @Override
    public Long zSize(String key) {
        return redisRouting().determineTargetEntity().zSize(key);
    }

    @Override
    public Long zZCard(String key) {
        return redisRouting().determineTargetEntity().zZCard(key);
    }

    @Override
    public Double zScore(String key, Object value) {
        return redisRouting().determineTargetEntity().zScore(key, value);
    }

    @Override
    public Long zRemoveRange(String key, long start, long end) {
        return redisRouting().determineTargetEntity().zRemoveRange(key, start, end);
    }

    @Override
    public Long zRemoveRangeByScore(String key, double min, double max) {
        return redisRouting().determineTargetEntity().zRemoveRangeByScore(key, min, max);
    }

    @Override
    public Long zUnionAndStore(String key, String otherKey, String destKey) {
        return redisRouting().determineTargetEntity().zUnionAndStore(key, otherKey, destKey);
    }

    @Override
    public Long zUnionAndStore(String key, Collection<String> otherKeys, String destKey) {
        return redisRouting().determineTargetEntity().zUnionAndStore(key, otherKeys, destKey);
    }

    @Override
    public Long zIntersectAndStore(String key, String otherKey, String destKey) {
        return redisRouting().determineTargetEntity().zIntersectAndStore(key, otherKey, destKey);
    }

    @Override
    public Long zIntersectAndStore(String key, Collection<String> otherKeys, String destKey) {
        return redisRouting().determineTargetEntity().zIntersectAndStore(key, otherKeys, destKey);
    }

    @Override
    public Cursor<ZSetOperations.TypedTuple<Object>> zScan(String key, ScanOptions options) {
        return redisRouting().determineTargetEntity().zScan(key, options);
    }
}
